<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
	<title>抽奖活动管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function () {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function (form) {
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function (error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
</head>
<body>
<ul class="nav nav-tabs">
	<li><a href="${ctx}/lottery/activity/">抽奖活动列表</a></li>
	<li class="active"><a href="${ctx}/lottery/activity/form?id=${activity.id}">抽奖活动<shiro:hasPermission
			name="lottery:activityedit">${not empty activity.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission
			name="lottery:activity:edit">查看</shiro:lacksPermission></a></li>
</ul>
<br/>
<form:form id="inputForm" modelAttribute="activity" action="${ctx}/lottery/activity/save" method="post"
		   class="form-horizontal">
	<form:hidden path="id"/>
	<sys:message content="${message}"/>
	<div class="control-group">
		<label class="control-label">微信用户：</label>
		<div class="controls">
			<form:select path="openid" class="input-xlarge ">
				<form:option value="" label=""/>
				<c:forEach var="manager" items="${managerList}">
					<form:option value="${manager.id}" label="${manager.nickname}"/>
				</c:forEach>
			</form:select>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">活动名称：</label>
		<div class="controls">
			<form:input path="name" htmlEscape="false" maxlength="255" class="input-xlarge "/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">活动图片url：</label>
		<div class="controls">
			<form:hidden id="image" path="image" htmlEscape="false" maxlength="255" class="input-xlarge"/>
			<sys:ckfinder input="image" type="files" uploadPath="/lottery/activity" selectMultiple="false"/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">活动奖品：</label>
		<div class="controls">
			<div id="prizeclass">
				<c:choose>
					<c:when test="${prizeList.size()==0}">
						<input type="hidden" name="prize_id" id="prize_id">
						奖品等级：<input type="text" id="prize_description" name="prize_description">
						奖品名称：<input type="text" id="prize_name" name="prize_name">
						奖品数量：<input type="text" id="prize_quantity" name="prize_quantity">
					</c:when>
					<c:otherwise>
						<input type="hidden" name="prize_id" id="prize_id" value="${prizeList.get(0).id}">
						奖品等级：<input type="text" id="prize_description" name="prize_description"
						value="${prizeList.get(0).description}">
						奖品名称：<input type="text" id="prize_name" name="prize_name" value="${prizeList.get(0).name}">
						奖品数量：<input type="text" id="prize_quantity" name="prize_quantity" value="${prizeList.get(0).quantity}">
					</c:otherwise>
				</c:choose>
				<button type="button" id="add_prize">添加</button>
				<br>
			</div>
			<c:if test="${prizeList.size()>1}">
				<c:forEach begin="1" items="${prizeList}" var="p">
					<div>
						<input type="hidden" name="prize_id" value="${p.id}">
						奖品等级：<input type="text" name="prize_description" value="${p.description}">
						奖品名称：<input type="text" name="prize_name" value="${p.name}">
						奖品数量：<input type="text" name="prize_quantity" value="${p.quantity}">
						<button type="button" onclick="del(this)">删除</button>
						<br>
					</div>
				</c:forEach>
			</c:if>
			<script type="text/javascript">
				var add = document.getElementById('add_prize');
				var container = document.getElementById('prizeclass');
				var node = container.nextSibling;

				function test(test) {
					test.parentNode.parentNode.removeChild(test.parentNode);
				}

				add.onclick = function () {
					oDiv = document.createElement('div');
					oDiv.innerHTML = '奖品等级：<input type="text" id="prize_description" name="prize_description">\n奖品名称：<input type="text" id="prize_name" name="prize_name">\n奖品数量：<input type="text" id="prize_quantity" name="prize_quantity">\n<button type="button" onclick="del(this)">删除</button>';
					container.parentNode.insertBefore(oDiv, node)
					node = oDiv.nextSibling;
				}

				function del(a) {
					a.parentNode.parentNode.removeChild(a.parentNode);
				}

				function clickPrizeClass() {
					//由于是弹出的面板，所以要自己写一个jsp
					top.$.jBox.open();
				};
			</script>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">详情介绍：</label>
		<div class="controls">
			<form:textarea id="detail" htmlEscape="false" path="detail" rows="4" maxlength="200" class="input-xxlarge"/>
			<sys:ckeditor replace="detail" uploadPath="/lottery/activity"/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">开始时间：</label>
		<div class="controls">
			<input name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
				   value="<fmt:formatDate value="${activity.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
				   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">结束时间：</label>
		<div class="controls">
			<input name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
				   value="<fmt:formatDate value="${activity.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>"
				   onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">参与人数限制：</label>
		<div class="controls">
			<form:input path="minNum" htmlEscape="false" maxlength="64" class="input-xlarge "/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">状态编码：</label>
		<div class="controls">
			<form:select path="statusId" class="input-xlarge ">
				<form:option value="" label=""/>
				<c:forEach var="status" items="${statusList}">
					<form:option value="${status.id}" label="${status.description}"/>
				</c:forEach>
			</form:select>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">状态解释：</label>
		<div class="controls">
			<form:input path="explanation" htmlEscape="false" maxlength="255" class="input-xlarge "/>
		</div>
	</div>
	<div class="control-group">
		<label class="control-label">开奖形式编码：</label>
		<div class="controls">
			<form:select path="formId" class="input-xlarge ">
				<form:option value="" label=""/>
				<c:forEach var="form" items="${formList}">
					<form:option value="${form.id}" label="${form.description}"/>
				</c:forEach>
			</form:select>
		</div>
	</div>
	<div class="form-actions">
		<shiro:hasPermission name="lottery:activity:edit"><input id="btnSubmit" class="btn btn-primary"
																		   type="submit"
																		   value="保 存"/>&nbsp;</shiro:hasPermission>
		<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
	</div>
</form:form>
</body>
</html>